package com.potato.base.base;

import android.os.Bundle;

import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.potato.base.mvp.IView;

public abstract class BaseActivity <P extends BasePresenter> extends AppCompatActivity implements IView {

    private P mPresenter;
    public abstract P loadPresenter();
    public abstract void initData();
    public abstract void initView();
    public abstract @LayoutRes int layoutId();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutId());
        mPresenter=loadPresenter();
        if (mPresenter!=null){
            mPresenter.attachView(this);
        }
        initView();
        initData();
        initEvent();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter!=null)
            mPresenter.detachView();
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    public void initEvent(){}
}
